import dayjs from 'dayjs';
import moment from 'moment';
import weekday from 'dayjs/plugin/weekday';
import advancedFormat from 'dayjs/plugin/advancedFormat';
import customParseFormat from 'dayjs/plugin/customParseFormat';
import localeData from 'dayjs/plugin/localeData';
import weekOfYear from 'dayjs/plugin/weekOfYear';
import weekYear from 'dayjs/plugin/weekYear';

dayjs.extend(weekday);
dayjs.extend(advancedFormat);
dayjs.extend(customParseFormat);
dayjs.extend(localeData);
dayjs.extend(weekOfYear);
dayjs.extend(weekYear);
export const formatDate = (dateArray: { [k: string]: Array }, key: string, format: string) => {
  dateArray &&
    dateArray.forEach((element: any) => {
      element[key] = moment(element[key]).format(format);
    });
  return dateArray;
};

export const formatDateDayjs = (dateArray: { [k: string]: Array }, key: string, format: string) => {
  dateArray &&
    dateArray.forEach((element: any) => {
      if (!!element[key]) {
        element[key] = dayjs(element[key], format);
      } else {
        element[key] = null;
      }
    });
  return dateArray;
};
// export default formatDate;
